class TheoryContent {
  String id;
  String jing;
  String summary;
  String pathogenesis;
  String symptoms;
  String therapy;
  String formula;
  bool isFavorite;
  bool hasNote;
  bool isKey;
  double progress;
  DateTime? lastStudyTime;
  String? note;

  TheoryContent({
    required this.id,
    required this.jing,
    required this.summary,
    required this.pathogenesis,
    required this.symptoms,
    required this.therapy,
    required this.formula,
    this.isFavorite = false,
    this.hasNote = false,
    this.isKey = false,
    this.progress = 0.0,
    this.lastStudyTime,
    this.note,
  });

  factory TheoryContent.fromMap(Map<String, dynamic> map) {
    return TheoryContent(
      id: map['id'],
      jing: map['jing'],
      summary: map['summary'],
      pathogenesis: map['pathogenesis'],
      symptoms: map['symptoms'],
      therapy: map['therapy'],
      formula: map['formula'],
      isFavorite: map['isFavorite'] == 1,
      hasNote: map['hasNote'] == 1,
      isKey: map['isKey'] == 1,
      progress: map['progress'] != null ? (map['progress'] is int ? map['progress'].toDouble() : map['progress']) : 0.0,
      lastStudyTime: map['lastStudyTime'] != null && map['lastStudyTime'] != '' ? DateTime.tryParse(map['lastStudyTime']) : null,
      note: map['note'],
    );
  }

  Map<String, dynamic> toMap() {
    return {
      'id': id,
      'jing': jing,
      'summary': summary,
      'pathogenesis': pathogenesis,
      'symptoms': symptoms,
      'therapy': therapy,
      'formula': formula,
      'isFavorite': isFavorite ? 1 : 0,
      'hasNote': hasNote ? 1 : 0,
      'isKey': isKey ? 1 : 0,
      'progress': progress,
      'lastStudyTime': lastStudyTime?.toIso8601String() ?? '',
      'note': note,
    };
  }
} 